﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.sys;
using Domain.Entity.tr;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Allot_hService
{
    public class Allot_hService : IAllot_hService
    {
        private readonly IAllot_hRepository allot_hRepository;
        private readonly IAllot_dRepository allot_dRepository;
        private readonly IDictDataRepository dictDataRepository;
        private readonly IMapper mapper;
        public Allot_hService(IAllot_hRepository allot_hRepository, IMapper mapper, IAllot_dRepository allot_dRepository, IDictDataRepository dictDataRepository)
        {
            this.allot_hRepository = allot_hRepository;
            this.allot_dRepository = allot_dRepository;
            this.dictDataRepository = dictDataRepository;
            this.mapper = mapper;
        }

        public Task<List<Allot_h>> GetAll()
        {
            throw new NotImplementedException();
        }

        public async Task<int> GetAudit(int id, int status, string user)
        {
            return await allot_hRepository.GetAudit(id, status, user);
        }

        public async Task<int> GetDelete(int id)
        {
            return await allot_hRepository.GetDelete(id);
        }

        public async Task<FenYe<Allot_h>> GetFenYe(FenYe<Allot_h> fenYe, string? al_code, int? al_status, int? instockoutstock_status, string? startTime, string? endTime)
        {
            return await allot_hRepository.GetFenYe(fenYe, al_code, al_status, instockoutstock_status, startTime, endTime);
        }

        public async Task<FenYe<Allot_h>> GetSeniorFenYe(FenYe<Allot_h> fenYe, string? al_code, int? al_status, int[]? instock_status, int[]? outstock_status, string? startTime, string? endTime, string? al_type, int? out_wh_id, int? in_wh_id, string? al_user, string? create_name, string? createstartTime, string? createendTime, string? auditstartTime, string? auditendTime, string? approver_name)
        {
            return await allot_hRepository.GetSeniorFenYe(fenYe, al_code, al_status, instock_status, outstock_status, startTime, endTime, al_type, out_wh_id, in_wh_id, al_user, create_name, createstartTime, createendTime, auditstartTime, auditendTime, approver_name);
        }

        public async Task<int> AddAudit(AddAllotDto addAllotDto)
        {
            Allot_h allot_h = mapper.Map<Allot_h>(addAllotDto.addAllot_hDto);
            List<Allot_d> allot_d = mapper.Map<List<Allot_d>>(addAllotDto.addAllot_dSDto);
            return await allot_hRepository.AddAudit(allot_h, allot_d);
        }

        public async Task<int> UpdateAudit(UpdateAllotDto updateAllotDto)
        {
            Allot_h allot_h = mapper.Map<Allot_h>(updateAllotDto.updateAllot_hDto);
            List<Allot_d> allot_d = mapper.Map<List<Allot_d>>(updateAllotDto.addAllot_dSDto);
            return await allot_hRepository.UpdateAudit(allot_h, allot_d);
        }

        public async Task<Allot_h> GetId(int id)
        {
            return await allot_hRepository.GetId(id);
        }

        public async Task<List<Allot_h>> GetAllot_Hs(string name)
        {
            return await allot_hRepository.GetAllot_Hs(name);
        }

        public async Task<int> Getid(string code)
        {
            return await allot_hRepository.Getid(code);
        }

        public async Task<int> UpdateStatus(string nameok, int oknum, string nameno, int nonum, string name, int alid)
        {
            return await allot_hRepository.UpdateStatus(nameok, oknum, nameno, nonum, name, alid);
        }

        public async Task<AllotTotals> Gettotal(string? proc_code, string? al_code, string? al_type, string? header_create_by, int? type_id, string? proc_primary_unit, string? al_user, int? out_wh_id, int? in_wh_id, int[] instock_status, int[] outstock_status, string? startTime, string? endTime, string? createstartTime, string? createendTime)
        {
            return await allot_hRepository.Gettotal(proc_code, al_code, al_type, header_create_by, type_id, proc_primary_unit, al_user, out_wh_id, in_wh_id, instock_status, outstock_status, startTime, endTime, createstartTime, createendTime);
        }

        public async Task<List<Allot_h>> GetByPid(int procid)
        {
            return await allot_hRepository.GetByPid(procid);
        }
    }
}
